package work.managercenter;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import utils.MyUtils;

public class BauxiteTextSiteRetriever {

	private static final String bauxiteTextUrl = "http://bauxitevm12.internetbrands.com:8080/dwr/exec/SiteTextManager.getTextAreasForDomainPageAndLanguage.dwr";
	private static final String bauxiteLoginCookieValue = "ibAutoLoginCookie=gmarcone|nFlyQNr9Vifh7NNKdZNC1cR42rvOIEPgZhG0eieCmZmYV0U8LWJnL0LYfL90KAbFtkZQhTqErAzB"
			+ "L25fFTXxrnoAC8SfiwmljWAGDEEVGajl031rPkTHmfx7YvyA8tMqhFfgRKN2kdKsIWegytuQitzSYA9XA1v9wcAdtlnX2fsdqetOWV4Y"
			+ "E5uq5tD8cCggb8ivj0cGVzQ3VadRVogT5JzLDKvOjA5G8Ukj7Izpn9UWfShObYkhDy7HpjdinWL";
	private static String[] bauxiteUrls = new String[] { "/PIE.htc", "/manager", "/manager/account", "/manager/admin", "/manager/admin/edit/{managerId}", "/manager/admin/login",
			"/manager/admin/logout", "/manager/admin/merge", "/manager/admin/reports/dailyRevenueSnapshot", "/manager/admin/reports/dateRangeRevenueSnapshot",
			"/manager/admin/reports/expiredCommunities", "/manager/admin/reports/expiringCommunities", "/manager/admin/reports/warmLeads", "/manager/admin/superadmin",
			"/manager/admin/testpagelayout", "/manager/admin/tools/addMonthlyRevenue", "/manager/admin/tools/addVRP", "/manager/admin/tools/subscriptions", "/manager/communities",
			"/manager/communities/addcommunity", "/manager/communities/invoice", "/manager/communities/legalagreement", "/manager/communities/payment", "/manager/communities/receipt",
			"/manager/community/{complexId}", "/manager/community/{complexId}/edit", "/manager/community/{complexId}/review-{reviewId}", "/manager/dashboard", "/manager/faq", "/manager/leads",
			"/manager/loading", "/manager/login", "/manager/login/password-reset-request", "/manager/login/password-reset-request-confirmation", "/manager/login/reset-password",
			"/manager/login/resetpassword", "/manager/logout", "/manager/managers", "/manager/managers/{managerId}", "/manager/oldlogin", "/manager/register/agreement",
			"/manager/register/communities", "/manager/register/invoice", "/manager/register/payment", "/manager/register/receipt", "/manager/register/userinfo", "/manager/reports",
			"/manager/reports/cachelargemcusers", "/manager/reports/cachelargemcusers", "/manager/reports/cachelargemcusers", "/manager/reports/citypropertyscores",
			"/manager/reports/communitytraffic", "/manager/reports/export", "/manager/reports/positivenegativereviews", "/manager/reports/ratingsreviewsvolume",
			"/manager/reports/reviewsresponsesvolume", "/manager/test/currencyformat", "/manager/test/stressTest-getOrderInvoiceHistory" };

	public static void main(String[] args) {
		try {
			DefaultHttpClient httpclient = new DefaultHttpClient();

			HttpPost httpost = new HttpPost(bauxiteTextUrl);
			httpost.setHeader("Cookie", bauxiteLoginCookieValue);

			List<NameValuePair> basePostParams = new ArrayList<NameValuePair>();
			basePostParams.add(new BasicNameValuePair("callCount", "1"));
			basePostParams.add(new BasicNameValuePair("c0-scriptName", "SiteTextManager"));
			basePostParams.add(new BasicNameValuePair("c0-methodName", "getTextAreasForDomainPageAndLanguage"));
			basePostParams.add(new BasicNameValuePair("c0-id", "3848_1348666773316"));
			basePostParams.add(new BasicNameValuePair("c0-param0", "string:apartmentratings.com"));
			basePostParams.add(new BasicNameValuePair("c0-param2", "string:en"));
			basePostParams.add(new BasicNameValuePair("c0-param3", "string:US"));
			basePostParams.add(new BasicNameValuePair("c0-param4", "string:"));
			basePostParams.add(new BasicNameValuePair("xml", "true"));

			for (String bauxiteURL: bauxiteUrls) {

				List<NameValuePair> postParams = new ArrayList<NameValuePair>(basePostParams);

				postParams.add(new BasicNameValuePair("c0-param1", "string:" + bauxiteURL));

				httpost.setEntity(new UrlEncodedFormEntity(postParams));
				HttpResponse response = httpclient.execute(httpost);

				print(bauxiteURL,response);
			}

			httpclient.getConnectionManager().shutdown();

		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}

	private static void print(String bauxiteURL, HttpResponse response) {
		try {
			String finalReturn = MyUtils.toString(response.getEntity().getContent(), null).replace(";var", ";" + MyUtils.EOL + "var");

			System.out.println(bauxiteURL + MyUtils.EOL + finalReturn + MyUtils.EOL + MyUtils.EOL);
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}

}
